package com.bss.model;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;

import com.andy.basics.AbstractEntity;

@Entity
@Table(name = "material")
public class Material extends AbstractEntity {

	/**
	 * 
	 */
	private static final long serialVersionUID = -8575390243131623144L;

	private int id;

	@NotNull
	private MaterialType materialType = new MaterialType();

	@NotNull
	@Size(min = 1, max = 50)
	private String name;

	@Min(1)
	private Integer instances;

	@Id
	@Column(name = "id", unique = true, nullable = false)
	@GeneratedValue(strategy = GenerationType.AUTO)
	public Integer getId() {
		return this.id;
	}

	@Override
	public void setId(final int id) {
		this.id = id;
	}

	@ManyToOne(fetch = FetchType.EAGER)
	@JoinColumn(name = "idMaterialType")
	public MaterialType getMaterialType() {
		return this.materialType;
	}

	public void setMaterialType(final MaterialType materialtype) {
		this.materialType = materialtype;
	}

	@Column(name = "name", length = 45)
	public String getName() {
		return this.name;
	}

	public void setName(final String name) {
		this.name = name;
	}

	@Column(name = "instances")
	public Integer getInstances() {
		return this.instances;
	}

	public void setInstances(final Integer instances) {
		this.instances = instances;
	}

	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "date", length = 19)
	public Date getDate() {
		return this.date;
	}
}
